//
//  JZHLisViewController.m
//  极致荟
//
//  Created by hetao on 14-5-23.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHLisViewController.h"
#import "JZHLisTableViewCell.h"
#import "JZHBlackCardDetailViewController.h"
@interface JZHLisViewController ()
{
    NSString *imgPrefix;
    NSMutableArray *huDataArr;
}
@property (weak, nonatomic) IBOutlet UITableView *table;
@end

@implementation JZHLisViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    //设置左侧按钮
    self.navigationItem.title=@"历史活动";
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
    
    huDataArr=[[NSMutableArray alloc]init];
    [self loadHoHttpDataPage:1  isHistory:1];
}
- (void)loadHoHttpDataPage:(int)i   isHistory:(int) ishis
{
    
        [MMProgressHUD showWithStatus:@"数据加载中..."];
     NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:@"",@"clubDate",[NSNumber numberWithInt:i],@"page",[NSNumber numberWithInt:ishis],@"isHistory", nil];
    //NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:9],@"cityId",[NSNumber numberWithInt:i],@"page",[NSNumber numberWithInt:ishis],@"isHistory", nil];
    
    [HttpRequest httpRequestPost:JZHHTTPURL(@"club/clubList") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        
        if(rerurncode==0)
        {
            [MMProgressHUD dismiss];
            NSLog(@"%@",data);
            imgPrefix=[[data objectForKey:@"data"] objectForKey:@"imgPrefix"];
            NSArray *arr=[[data objectForKey:@"data"] objectForKey:@"list"];
            for(NSDictionary *datadic in arr)
            {
                //创建活动实体类
                JZHActivities *jzh=[[JZHActivities alloc]init];
                jzh.actdate=[NSDate dateWithTimeIntervalSince1970:[[datadic objectForKey:@"clubTime"]longLongValue]];
                jzh.actId=[[datadic objectForKey:@"id"] intValue];
                jzh.acttile=[datadic objectForKey:@"subject"];
                jzh.content=[datadic objectForKey:@"clubDetail"];
                jzh.actimage=[imgPrefix stringByAppendingString:[datadic objectForKey:@"coverImg"]];
                jzh.cityname=[datadic objectForKey:@"cityName"];
                [huDataArr addObject:jzh];
                [MMProgressHUD dismiss];
            }
            
        }else
        {
            [MMProgressHUD dismissWithError:@"暂无数据" afterDelay:1.0];
        }
             [self.table reloadData];
    }];
    
}

- (void)leftDrawerButtonPress:(UIButton*)but
{
    [UINavigationController Pop:self];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark ---tableview代理---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return huDataArr.count;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str=@"adf";
    JZHLisTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
    if(!cell)
    {
        cell=[[[NSBundle mainBundle]loadNibNamed:@"JZHLisTableViewCell" owner:self options:nil] objectAtIndex:0];
    }
    [cell setCellData:huDataArr[indexPath.row]];
   
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 94;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
   
    [self.navigationController pushViewController:[[JZHBlackCardDetailViewController alloc]initCommodity:huDataArr[indexPath.row]] animated:YES];
}


@end
